package com.zy.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.zy.utils.CanvasUtils;
import com.zy.utils.data.Point;

import java.util.List;

//堆
public class DIYCanvasView001 extends View {


    public DIYCanvasView001(Context context) {
        super(context);
        init(context);
    }


    public DIYCanvasView001(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DIYCanvasView001(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public DIYCanvasView001(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    Paint nodePaint;
    Paint textPaint;
    Paint indexPaint;
    Paint assistLinePaint;

    private void init(Context context) {
        nodePaint = new Paint();
        nodePaint.setColor(Color.WHITE);

        textPaint = new Paint();
        //设置文本大小
        textPaint.setTextSize(72);
        //设置文本对齐方式
        textPaint.setTextAlign(Paint.Align.CENTER);
        textPaint.setColor(Color.RED);

        indexPaint = new Paint();
        //设置文本大小
        indexPaint.setTextSize(36);
        indexPaint.setStyle(Paint.Style.STROKE);
        indexPaint.setStrokeWidth(5);
        //设置文本对齐方式
        indexPaint.setTextAlign(Paint.Align.CENTER);
        indexPaint.setColor(Color.BLUE);

        assistLinePaint = new Paint();
        assistLinePaint.setColor(Color.WHITE);
        DashPathEffect effects = new DashPathEffect(new float[]{5, 5, 5, 5}, 10);
        assistLinePaint.setPathEffect(effects);
    }

    int[] ss = new int[]{6, 5, 8, 7, 4, 3, 2, 1, 6, 5, 8, 7, 4, 3, 2, 1};
    int[] ss1 = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);


        int w = getWidth();
        int h = getHeight();

        canvas.drawLine(w >> 1, 0, w >> 1, h, textPaint);
        canvas.drawLine(0, h >> 1, w, h >> 1, textPaint);
        canvas.drawLine(0, 300, w, 300, textPaint);


        // canvas.save();

        // CanvasUtils.drawArray(canvas, ss, textPaint, indexPaint, w / 2, 300, 50, 50);
        CanvasUtils.drawArray(canvas, ss1, textPaint, indexPaint, w / 2, h >> 1, 50, 50);

        Point[] sss = CanvasUtils.drawArray1(ss, w / 2, 300, 50, 50);
        for (Point point : sss) {
            point.draw(canvas, textPaint, indexPaint);
        }

        // canvas.restore();

    }

}
